package com.coffeeloversupportlibrary.coffeelover.mercury.classify.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.coffeeloversupportlibrary.R;
import com.coffeeloversupportlibrary.coffeelover.mercury.entity.Comment;


import java.util.ArrayList;
import java.util.List;

import de.hdodenhof.circleimageview.CircleImageView;


/**
 * @author 盛守义
 * @createTime 2021/11/13 16:14
 * @projectName TurningCoffee
 * @className CommentAdapter.java
 * @description TODO
 */
public class CommentAdapter extends BaseAdapter {
    private List<Comment.DataDTO.CommentsDTO> comments = new ArrayList<>();
    private Context context;
    private int comment_item_id;

    private CircleImageView civ_img;
    private TextView tv_name, tv_comment, tv_date;

    public CommentAdapter(){    }

    public CommentAdapter(List<Comment.DataDTO.CommentsDTO> comments, Context context, int comment_item_id){
        this.comments = comments;
        this.context = context;
        this.comment_item_id = comment_item_id;
    }

    @Override
    public int getCount() {
        return comments.size();
    }

    @Override
    public Object getItem(int i) {
        return comments.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        LayoutInflater layoutInflater = LayoutInflater.from(context);
        View layout = layoutInflater.inflate(comment_item_id, null);

        civ_img = layout.findViewById(R.id.civ_imgcomment);
        tv_comment = layout.findViewById(R.id.tv_detailcomment);
        tv_name = layout.findViewById(R.id.tv_namecomment);
        tv_date = layout.findViewById(R.id.tv_detaildate);

        Glide.with(context).load(comments.get(i).getUserImg()).into(civ_img);
        tv_name.setText(comments.get(i).getUserNickname());
        tv_comment.setText(comments.get(i).getCoffeeComment());
        tv_date.setText(comments.get(i).getUpdateTime());

        return layout;
    }
}
